}
if ( ed->distance == BADVAL || ed->distance >= pos_dist ) {
if ( ptsopt ) {
- dist = gcdist( lat2*M_PI/180.0, lon2*M_PI/180.0,
- waypointp->latitude*M_PI/180.0,
- waypointp->longitude*M_PI/180.0 );
+ dist = gcdist( RAD(lat2), RAD(lon2),
+ RAD(waypointp->latitude),
+ RAD(waypointp->longitude) );
}
else {
dist = linedist(lat1, lon1, lat2, lon2,
#include "defs.h"
#include "coldsync/palm.h"
#include "coldsync/pdb.h"
-
-static double conv = 180.0 / M_PI;
+#include "grtcirc.h"
#define MYNAME "CoPilot Waypoint"
#define MYTYPE 0x77617970 /* wayp */
rec = (struct record *) pdb_rec->data;
wpt_tmp->longitude =
- -pdb_read_double(&rec->longitude) * conv;
+ DEG(-pdb_read_double(&rec->longitude));
wpt_tmp->latitude =
- pdb_read_double(&rec->latitude) * conv;
+ DEG(pdb_read_double(&rec->latitude));
wpt_tmp->altitude =
pdb_read_double(&rec->elevation) * .3048;
rec = xcalloc(sizeof(*rec)+1141,1);
- pdb_write_double(&rec->latitude, wpt->latitude / conv);
- pdb_write_double(&rec->longitude,
- -wpt->longitude / conv);
+ pdb_write_double(&rec->latitude, RAD(wpt->latitude));
+ pdb_write_double(&rec->longitude, RAD(-wpt->longitude));
pdb_write_double(&rec->elevation,
wpt->altitude / .3048);
pdb_write_double(&rec->magvar, 0);
#include "csv_util.h"
#include "coldsync/palm.h"
#include "coldsync/pdb.h"
+#include "grtcirc.h"
#define MYNAME "cotoGPS"
rec = (struct record_track *) pdb_rec->data;
- wpt_tmp->longitude = -pdb_read_double(&rec->longitude)*360.0/(2.0*M_PI);
- wpt_tmp->latitude = pdb_read_double(&rec->latitude)*360.0/(2.0*M_PI);
+ wpt_tmp->longitude = DEG(-pdb_read_double(&rec->longitude));
+ wpt_tmp->latitude = DEG(pdb_read_double(&rec->latitude));
// It's not the course, so leave it out for now
// wpt_tmp->course = pdb_read_double(&rec->arc);
rec = (struct record_wpt *) pdb_rec->data;
- wpt_tmp->longitude = -pdb_read_double(&rec->lon)*360.0/(2.0*M_PI);
- wpt_tmp->latitude = pdb_read_double(&rec->lat)*360.0/(2.0*M_PI);
+ wpt_tmp->longitude = DEG(-pdb_read_double(&rec->lon));
+ wpt_tmp->latitude = DEG(pdb_read_double(&rec->lat));
wpt_tmp->shortname = xstrndup(rec->name, sizeof(rec->name));
size += strlen(notes);
rec = xcalloc(size, 1);
- pdb_write_double(&rec->lon, -2.0*M_PI*wpt->longitude/360.0);
- pdb_write_double(&rec->lat, 2.0*M_PI*wpt->latitude/360.0);
+ pdb_write_double(&rec->lon, RAD(-wpt->longitude));
+ pdb_write_double(&rec->lat, RAD(wpt->latitude));
strncpy(rec->name, shortname, MAX_MARKER_NAME_LENGTH);
if (notes)
queue *elem, *tmp;
if ( oldlon < 900 ) {
- pathdist += radtomiles(gcdist(oldlat*M_PI/180,oldlon*M_PI/180,
- wpt->latitude*M_PI/180,wpt->longitude*M_PI/180));
+ pathdist += radtomiles(gcdist(RAD(oldlat),RAD(oldlon),
+ RAD(wpt->latitude),RAD(wpt->longitude)));
}
oldlon = wpt->longitude;
oldlat = wpt->latitude;
#include <errno.h>
#include <stdio.h>
#include "defs.h"
+#include "grtcirc.h"
static const double EARTH_RAD = 6378137.0;
int newpoints;
/* degrees to radians */
- lat1 *= M_PI/180.0; lon1 *= M_PI/180.0;
- lat2 *= M_PI/180.0; lon2 *= M_PI/180.0;
- lat3 *= M_PI/180.0; lon3 *= M_PI/180.0;
+ lat1 = RAD(lat1); lon1 = RAD(lon1);
+ lat2 = RAD(lat2); lon2 = RAD(lon2);
+ lat3 = RAD(lat3); lon3 = RAD(lon3);
newpoints = 1;
if ( lat1 == _lat1 && lat2 == _lat2 && lon1 == _lon1 && lon2 == _lon2) {
double sinphi = 0;
/* degrees to radians */
- lat1 *= M_PI/180.0; lon1 *= M_PI/180.0;
- lat2 *= M_PI/180.0; lon2 *= M_PI/180.0;
+ lat1 = RAD(lat1); lon1 = RAD(lon1);
+ lat2 = RAD(lat2); lon2 = RAD(lon2);
/* polar to ECEF rectangular */
x1 = cos(lon1)*cos(lat1); y1 = sin(lat1); z1 = sin(lon1)*cos(lat1);
if ( zr > 1 ) zr = 1;
if ( zr < -1 ) zr = -1;
- *reslat = asin(yr) * 180 / M_PI;
+ *reslat = DEG(asin(yr));
if( xr == 0 && zr == 0 ) {
*reslon = 0;
}
else {
- *reslon = atan2( zr, xr ) * 180 / M_PI;
+ *reslon = DEG(atan2( zr, xr ));
}
}
}
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
*/
+
+#ifndef GRTCIRC_H
+#define GRTCIRC_H
+
double gcdist( double lat1, double lon1, double lat2, double lon2 );
double heading( double lat1, double lon1, double lat2, double lon2 );
#define DEG(x) ((x)*180.0/M_PI)
#define RAD(x) ((x)*M_PI/180.0)
+
+#endif
}
}
else if ( opt_dist ) {
- rt1 = lat1 * M_PI / 180;
- rn1 = lon1 * M_PI / 180;
- rt2 = wpt->latitude * M_PI / 180;
- rn2 = wpt->longitude * M_PI / 180;
+ rt1 = RAD(lat1);
+ rn1 = RAD(lon1);
+ rt2 = RAD(wpt->latitude);
+ rn2 = RAD(wpt->longitude);
curdist = gcdist( rt1, rn1, rt2, rn2 );
curdist = radtomiles(curdist);
if ( curdist > dist ) {
QUEUE_FOR_EACH(&(hd->waypoint_list), elem, tmp)
{
waypointp = (waypoint *) elem;
- lat2 = waypointp->latitude *M_PI/180.0 ;
- lon2 = waypointp->longitude*M_PI/180.0 ;
+ lat2 = RAD(waypointp->latitude);
+ lon2 = RAD(waypointp->longitude);
if (i)
{
d = gcdist(lat1, lon1, lat2, lon2 );
while (elem!=&(hd->waypoint_list) && dd<dist/2.0)
{
waypointp = (waypoint *) elem;
- lat2 = waypointp->latitude *M_PI/180.0;
- lon2 = waypointp->longitude*M_PI/180.0;
+ lat2 = RAD(waypointp->latitude);
+ lon2 = RAD(waypointp->longitude);
if (i)
{
d = gcdist(lat1, lon1, lat2, lon2 );
// d = acos( sin(lats)*sin(late)+cos(lats)*cos(late)*cos(lone-lons) );
dd = acos( (sin(late) - sin(lats)*cos(d))/(cos(lats)*sin(d)) );
if (lone<lons) dd = -dd; // correction because the ambiguity of acos function
- dd = dd * 180.0/M_PI; // azimuth
+ dd = DEG(dd); // azimuth
dd = 360.0 - (dd + 270.0); // make it anticlockwise and start counting on x-axis
dd = dd < 0.0 ? dd + 360.0 : dd; // normalizing
dd = dd > 360.0 ? dd - 360.0 : dd; // normalizing
/* name of route */
/* plot text at the last point of route */
govl_dir = dd; // approximated text rotation, correct value must be the azimuth in UTM
- symbol_text(lon1*180.0/M_PI,lat1*180.0/M_PI,hd->rte_name,govl_group_cnt);
+ symbol_text(DEG(lon1),DEG(lat1),hd->rte_name,govl_group_cnt);
govl_dir = 0.0; // restore
}
gc_distance(double lat1, double lon1, double lat2, double lon2)
{
return gcdist(
- (lat1 * M_PI) / 180.0,
- (lon1 * M_PI) / 180.0,
- (lat2 * M_PI) / 180.0,
- (lon2 * M_PI) / 180.0
+ RAD(lat1),
+ RAD(lon1),
+ RAD(lat2),
+ RAD(lon2)
);
}
#include "defs.h"
#include "cet_util.h"
#include <ctype.h>
+#include "grtcirc.h"
#define MYNAME "PSP"
/* 8 bytes - latitude in radians */
radians = psp_fread_double(psp_file_in);
- lat = (radians * 180.0) / M_PI;
+ lat = DEG(radians);
/* 8 bytes - longitude in radians */
radians = psp_fread_double(psp_file_in);
- lon = (radians * 180.0) / M_PI;
+ lon = DEG(radians);
/* since we don't know the origin of this PSP file, we use */
/* the grid byte adjust longitude, if necessary, mimicing */
}
/* convert lat/long back to radians */
- lat = (wpt->latitude * M_PI) / 180.0;
- lon = (wpt->longitude * M_PI) / 180.0;
+ lat = RAD(wpt->latitude);
+ lon = RAD(wpt->longitude);
pindex++;
le_write16(tbuf, pindex);
if ( times ) {
if ( !first ) {
double dist = radtomiles(gcdist(
- lat*M_PI/180, -lon*M_PI/180,
- oldlat*M_PI/180,
- -oldlon*M_PI/180 ));
+ RAD(lat), RAD(-lon),
+ RAD(oldlat),
+ RAD(-oldlon) ));
totaldist += dist;
if ( totaldist > seglen ) {
totaldist = seglen;
#define MYNAME "vitosmt"
#include "defs.h"
+#include "grtcirc.h"
static FILE *infile =0;
static FILE *ofs =0;
wpt_tmp = waypt_new();
- wpt_tmp->latitude =(latrad * 180) / M_PI;
- wpt_tmp->longitude =(lonrad * 180) / M_PI;
+ wpt_tmp->latitude =DEG(latrad);
+ wpt_tmp->longitude =DEG(lonrad);
wpt_tmp->altitude =elev;
tmStruct.tm_year =timestamp[0]+100;
++count;
workbuffer = xcalloc(vitosmt_datasize,1);
- WriteDouble(&workbuffer[position], (M_PI*waypointp->latitude)/180 );
+ WriteDouble(&workbuffer[position], RAD(waypointp->latitude) );
position += sizeof(double);
- WriteDouble(&workbuffer[position], (M_PI*waypointp->longitude)/180 );
+ WriteDouble(&workbuffer[position], RAD(waypointp->longitude) );
position += sizeof(double);
if ( waypointp->altitude-1 > unknown_alt)
WriteDouble(&workbuffer[position], waypointp->altitude );